package com.ysucode.web.servlet;

import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/responseErrorServlet")
public class responseErrorServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        this.doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setCharacterEncoding("gbk");
        FileInputStream fileInputStream = new FileInputStream("D:\\JAVA\\WorkSpace\\YsuCode-demo\\tmp\\compile_error.txt");
        response.setHeader("Content-Type", "text/html;charset=GBK");
        ServletOutputStream outputStream = response.getOutputStream();
        int len;
        byte[] by = new byte[1024];
        while ((len = fileInputStream.read(by)) != -1) {
            outputStream.write(by, 0, len);
        }
    }
}
